<?php
/*******************************************************************************
itemDisplayer.class.php

Created by Dmitriy Panteleyev (dpantel@emory.edu)
Modified by NCSU Libraries, NC State University. Modifications by Karl Doerr and Troy Hurteau (libraries.opensource@ncsu.edu).

This file is part of NCSU's distribution of ReservesDirect. This version has not been downloaded from Emory University
or the original developers of ReservesDirect. Neither Emory University nor the original developers of ReservesDirect have authorized
or otherwise endorsed or approved this distribution of the software.

Copyright (c) 2004-2006 Emory University, Atlanta, Georgia.

Licensed under the NCSU ReservesDirect License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. You may obtain a copy of the full License at
 http://www.lib.ncsu.edu/it/opensource/

ReservesDirect is distributed in the hope that it will be useful,
but is distributed "AS IS" and WITHOUT ANY WARRANTY, without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE, and without any warranty as to non-infringement of any third
party's rights. See the License for the specific language governing permissions and limitations under the License.

The original version of ReservesDirect is located at:
http://www.reservesdirect.org/

This version of ReservesDirect, distributed by NCSU, is located at:
http://code.google.com/p/reservesdirect-ncsu/

*******************************************************************************/

require_once(APPLICATION_PATH . '/classes/copyright.class.php');
require_once(APPLICATION_PATH . '/classes/reserves.class.php');
require_once(APPLICATION_PATH . '/displayers/noteDisplayer.class.php');
require_once(APPLICATION_PATH . '/displayers/copyrightDisplayer.class.php');
require_once(APPLICATION_PATH . '/managers/ajaxManager.class.php');
require_once(APPLICATION_PATH . '/lib/Rd/Request.php');

class itemDisplayer extends noteDisplayer {

	protected $_displayerName = 'item';
	
	/**
	 * @return void
	 * @param reserveItem $item reserveItem object
	 * @param reserve $reserve (optional) reserve object
	 * @param array $dub_array (optional) array of information pertaining to duplicating an item. currently 'dubReserve' flag and 'selected_instr'
	 * @desc Displays form for editing item information (optionally: reserve information)
	 */
	function displayEditItem($model) 
	{ //$item, $reserve = NULL, $dub_array = NULL) {
		//determine if editing a reserve
		if(!empty($model['reserve']) && ($model['reserve'] instanceof reserve)) {
			$model['editReserve'] = TRUE;
			$model['editItemHref'] = 'reserveID=' . $model['reserve']->getReserveID();			
		}
		else {
			$model['editReserve'] = FALSE;
			$model['editItemHref'] = 'itemID=' . $model['item']->getItemID();
		}
		$this->display('edit', $model);
	}
	
	
	/**
	 * @return void
	 * @param reserveItem object $reserveItem
	 * @desc Displays the edit-item-source block
	 */
	function displayEditItemSource($model)
	{ 
		$this->display('editSource', $model);
	}
	
	
	/**
	 * @return void
	 * @param Reserve object $reserve
	 * @desc Displays the edit-item-reserve-details block
	 */
	function displayEditItemReserveDetails($model) {
		global $calendar;
		$model['calendar'] = $calendar;
		$this->display('editReserveDetails', $model);
	}
	
	
	/**
	* @return void
	* @param reserveItem $item reserveItem object
	* @desc Displays the edit-item-item-details block
	*/	
	function displayEditItemItemDetails($model)//$item) 
	{
		$model['catalogName'] = Rd_Registry::get('root:catalogName');
		$model['iconTypes'] = $this->_user->getAllDocTypeIcons(TRUE);
		$this->display('editDetails', $model);
	}
	
	
	/**
	 * @return void
	 * @param reserveItem $item reserveItem object
	 * @param reserves $reserve (optional) reserve object
	 * @desc Displays the edit-item-notes block
	 */	
	function displayEditItemNotes($model)//$item, $reserve=null) 
	{		
		$this->display('editNodes', $model);
	}
	

	/**
 	 * @return void
	 * @param reserveItem $item reserveItem object
	 * @param reserves $reserve (optional) reserve object
	 * @desc Displays the edit-item-notes block
	 */	
	function displayEditItemNotesAJAX($model)//$item, $reserve=null) 
	{
		$this->display('notesAjax', $model);
	}
	
	
	/**
	 * @return void
	 * @param reserveItem $item reserveItem object
	 * @param reserves $reserve (optional) reserve object
	 * @param array $dub_array (optional) array of information pertaining to duplicating an item. currently 'dubReserve' flag and 'selected_instr'
	 * @desc Displays form for editing item information (optionally: reserve information)
	 */	
	function displayEditItemMeta($model)
	{ //($item, $reserve=null, $dub_array=null) {
		$this->display('editMeta', $model);
	}
	
	/**
	 * @return void
	 * @param reserveItem object $item
	 * @desc Displays item history screen
	 */
	function displayItemHistory($model)//$item, $highlightedReserve = NULL) 
	{
		$this->display('editHistory', $model);
	}
	
	function displayItemPhysicalCopies($model) //$item) {
	{ 
		$model['ils'] = Rd_Registry::get('root:ils');
		$this->display('editItemPhysicalCopies', $model);
	}
	
	/**
	 * @return void
	 * @param reserveItem object $item
	 * @desc Displays item status screen
	 */
	function displayItemStatus($model) //$item, $reserve) 
	{
		global $g_recordDisplay;
		$model['catalogRecordUrl'] = $g_recordDisplay;
		$model['ils'] = Rd_Registry::get('root:ils');
		$this->display('status', $model);
	}

	
	function displayEditHeadingScreen($model) 
	{
		global $calendar;
		$model['calendar'] = $calendar;
		$this->display('editHeading', $model);  
	}

	
	/**
	* @return void
	* @param int $ci_id courseInstance ID
	* @param string $search_serial serialized search _request
	* @desc Displays editItem/editReserve success screen
	*/	
	function displayItemSuccessScreen($model) //$ci_id=null, $search_serial=null)	
	{		
		$this->display('itemSuccess', $model);
	}
	
	/**
	* @return void
	* @param int $ci_id courseInstance ID
	* @desc Displays editHeading success screen
	*/	
	function displayHeadingSuccessScreen($model) //$ci_id=null)	
	{		
		$this->display('headingSuccess', $model);
	}

	//#TODO the below features are probably deprecated...
	
	/**
	 * @return void
	 * @param reserveItem object $item
	 * @desc Displays item-copyright edit screen
	 */
	function displayEditItemCopyright($model) //$item) 
	{
		$copyright = new Copyright($item->getItemID());

		//get copyright library
		$home_lib_id = $item->getHomeLibraryID();
		if(!empty($home_lib_id)) {
			$home_lib = new library($home_lib_id);
			$copyright_lib = new library($home_lib->getCopyrightLibraryID());
			$copyright_lib_name = $copyright_lib->getLibrary();
		}
		else {
			$copyright_lib_name = 'n/a';
		}
		
		//get status basis
		$status_basis = $copyright->getStatusBasis();
		$status_basis = !empty($status_basis) ? $status_basis : 'n/a';
		
		//get contact name
		$contact = $copyright->getContact();
		$contact_org = $contact['org_name'];
?>
	<script language="JavaScript1.2" src="public/javascript/liveSearch.js"></script>
	<script language="JavaScript1.2" src="public/javascript/basicAJAX.js"></script>
	<script language="JavaScript1.2" src="public/javascript/notes_ajax.js"></script>
	<script language="JavaScript1.2" src="public/javascript/copyright_ajax.js"></script>
	
	<script language="JavaScript">
		function toggleDisplay(element_id, show) {
			if(document.getElementById(element_id)) {
				if(show) {				
					document.getElementById(element_id).style.display = '';
				}
				else {
					document.getElementById(element_id).style.display = 'none';
				}
			}
		}
	</script>
		
	<div id="copyright" class="displayArea">
		<div class="headingCell1">SUMMARY</div>
		<table width="100%" class="simpleList">
			<tr>
				<td width="150" class="labelCell1"><strong>Current Status:</strong></td>
				<td width="150" class="<?php print($copyright->getStatus()); ?>"><?php print($copyright->getStatus()); ?></td>
				<td width="150" class="labelCell1"><strong>Review Library:</strong></td>
				<td><?php print($copyright_lib_name);?></td>
			</tr>
			<tr>
				<td width="150" class="labelCell1"><strong>Reason:</strong></td>
				<td><?php print($status_basis); ?></td>
				<td width="150" class="labelCell1"><strong>Copyright Contact:</strong></td>
				<td><?php print($contact_org); ?></td>
			</tr>		
		</table>
<?php
		self::displayEditItemCopyrightStatus($item->getItemID());
		
		//only show the rest of the sections if the record exists
		$copyright_id = $copyright->getID();
		if(!empty($copyright_id)) {
			self::displayEditItemCopyrightContact($item->getItemID());
			self::displayEditItemCopyrightNotes($item->getItemID());
			self::displayEditItemCopyrightFiles($item->getItemID());
			self::displayEditItemCopyrightLog($item->getItemID());	
		}
?>	
	</div>
<?php	
	}
	
	
	/**
	 * @return void
	 * @desc Displays form to edit copyright status.
	 */
	function displayEditItemCopyrightStatus($model) //$item_id) 
	{
		$copyright = new Copyright($item_id);
?>
		<div class="contentTabs" style="text-align:center; border-top:1px solid #333333;"><a href="#" onclick="javascript: toggleDisplay('copyright_edit_status', 1); return false;">STATUS</a></div>
		<div id="copyright_edit_status" style="border-top:1px solid #333333; padding:10px; display:none;">		
			<?php copyrightDisplayer::displayCopyrightEditStatus($item_id, $copyright->getStatus(), $copyright->getStatusBasisID()); ?>	
			<input type="button" name="cancel" value="Close" onclick="javascript: toggleDisplay('copyright_edit_status', 0);" />
		</form>
		</div>
<?php
	}
	
	
	/**
	 * @return void
	 * @desc Displays form to edit copyright status.
	 */
	function displayEditItemCopyrightContact($model) //$item_id) 
	{
?>		
		<div class="contentTabs" style="text-align:center; border-top:1px solid #333333;"><a href="#" onclick="javascript: toggleDisplay('copyright_contact', 1); return false;">CONTACT</a></div>
		<div id="copyright_contact" style="border-top:1px solid #333333; padding:10px; display:none;">
			<?php copyrightDisplayer::displayCopyrightContactsBlockAJAX($item_id, true, true); ?>
			<input type="button" name="cancel" value="Close" onclick="javascript: toggleDisplay('copyright_contact', 0);" />
		</div>
<?php
	}
	
	
	/**
	 * @return void
	 * @param int $item_id ID of item
	 * @desc Displays copyright notes.
	 */
	function displayEditItemCopyrightNotes($model) //$item_id) 
	{
		//fetch notes
		$notes = noteManager::fetchNotesForObj('copyright', $item_id);
?>
		<div class="contentTabs" style="text-align:center; border-top:1px solid #333333;"><a href="#" onclick="javascript: toggleDisplay('copyright_notes', 1); return false;">NOTES</a></div>
		<div id="copyright_notes" style="border-top:1px solid #333333; padding:10px; display:none;">
			<?php self::displayNotesBlockAJAX($notes, 'copyright', $item_id, true); ?>
			<input type="button" name="cancel" value="Close" onclick="javascript: toggleDisplay('copyright_notes', 0);" />
		</div>
<?php
	}
	
	
	/**
	 * @return void
	 * @param int $item_id ID of item
	 * @desc Displays copyright files.
	 */
	function displayEditItemCopyrightFiles($model) //$item_id) 
	{
		
?>
		<div class="contentTabs" style="text-align:center; border-top:1px solid #333333;"><a href="#" onclick="javascript: toggleDisplay('copyright_files', 1); return false;">SUPPORTING FILES</a></div>
		<div id="copyright_files" style="border-top:1px solid #333333; padding:10px; display:none;">
		
<span style="color:red">DELETE ACTUAL FILE ON DELETE?</span>
<br /><br />

			<?php copyrightDisplayer::displayCopyrightSupportingFile($item_id); ?>
			<input type="button" name="cancel" value="Close" onclick="javascript: toggleDisplay('copyright_files', 0);" />
		</div>
<?php
	}
	

	/**
	 * @return void
	 * @desc Displays copyright log.
	 */
	function displayEditItemCopyrightLog($model) //$item_id) 
	{
?>
		<div class="contentTabs" style="text-align:center; border-top:1px solid #333333;"><a href="#" onclick="javascript: toggleDisplay('copyright_log', 1); return false;">LOG</a></div>
		<div id="copyright_log" style="display:none;">
			<?php copyrightDisplayer::displayCopyrightLogs($item_id); ?>
			<input type="button" name="cancel" value="Close" onclick="javascript: toggleDisplay('copyright_log', 0);" />
		</div>
<?php
	}
	
}
